package com.ruoyi.am.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.am.mapper.AmRosterMapper;
import com.ruoyi.am.domain.AmRoster;
import com.ruoyi.am.service.IAmRosterService;
import com.ruoyi.common.core.text.Convert;

/**
 * 排班管理Service业务层处理
 * 
 * @author hkkk
 * @date 2020-12-04
 */
@Service
public class AmRosterServiceImpl implements IAmRosterService 
{
    @Autowired
    private AmRosterMapper amRosterMapper;

    /**
     * 查询排班管理
     * 
     * @param rosterId 排班管理ID
     * @return 排班管理
     */
    @Override
    public AmRoster selectAmRosterById(Long rosterId)
    {
        return amRosterMapper.selectAmRosterById(rosterId);
    }

    /**
     * 查询排班管理列表
     * 
     * @param amRoster 排班管理
     * @return 排班管理
     */
    @Override
    public List<AmRoster> selectAmRosterList(AmRoster amRoster)
    {
        return amRosterMapper.selectAmRosterList(amRoster);
    }

    /**
     * 新增排班管理
     * 
     * @param amRoster 排班管理
     * @return 结果
     */
    @Override
    public int insertAmRoster(AmRoster amRoster)
    {
        return amRosterMapper.insertAmRoster(amRoster);
    }

    /**
     * 修改排班管理
     * 
     * @param amRoster 排班管理
     * @return 结果
     */
    @Override
    public int updateAmRoster(AmRoster amRoster)
    {
        return amRosterMapper.updateAmRoster(amRoster);
    }

    /**
     * 删除排班管理对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteAmRosterByIds(String ids)
    {
        return amRosterMapper.deleteAmRosterByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除排班管理信息
     * 
     * @param rosterId 排班管理ID
     * @return 结果
     */
    @Override
    public int deleteAmRosterById(Long rosterId)
    {
        return amRosterMapper.deleteAmRosterById(rosterId);
    }

    @Override
    public List<AmRoster> selectAmRosterByMonth(int month)
    {
        return amRosterMapper.selectAmRosterByMonth(month);
    }

    @Override
    public AmRoster selectAmRosterByName(String name) {
        return amRosterMapper.selectAmRosterByName(name);
    }

    @Override
    public AmRoster selectAmRosterByNameAndMonth(String name, String month) {
        return amRosterMapper.selectAmRosterByNameAndMonth(name, month);
    }

    @Override
    public int deleteAmRosterByMonth(Long month){
        return amRosterMapper.deleteAmRosterByMonth(month);
    }

    @Override
    public String selectTime(String driver, String month) {
        AmRoster amRoster=amRosterMapper.selectAmRosterByNameAndMonth(driver,month);
        int day=0,night=0;
        if(amRoster!=null) {
            for (int i = 1; i <= 31; i++) {
                String status=getDs(amRoster, i);
                if (!status.equals("")&&status.contains("白")) {
                    day++;
                }
                else if (!status.equals("")&&status.contains("夜")){
                    night++;
                }
            }
        }
        return day+":"+night;
    }

    public String getDs(AmRoster amRoster,int day){
        String order="";
        switch (day){
            case 1:order=amRoster.getD1();break;
            case 2:order=amRoster.getD2();break;
            case 3:order=amRoster.getD3();break;
            case 4:order=amRoster.getD4();break;
            case 5:order=amRoster.getD5();break;
            case 6:order=amRoster.getD6();break;
            case 7:order=amRoster.getD7();break;
            case 8:order=amRoster.getD8();break;
            case 9:order=amRoster.getD9();break;
            case 10:order=amRoster.getD10();break;
            case 11:order=amRoster.getD11();break;
            case 12:order=amRoster.getD12();break;
            case 13:order=amRoster.getD13();break;
            case 14:order=amRoster.getD14();break;
            case 15:order=amRoster.getD15();break;
            case 16:order=amRoster.getD16();break;
            case 17:order=amRoster.getD17();break;
            case 18:order=amRoster.getD18();break;
            case 19:order=amRoster.getD19();break;
            case 20:order=amRoster.getD20();break;
            case 21:order=amRoster.getD21();break;
            case 22:order=amRoster.getD22();break;
            case 23:order=amRoster.getD23();break;
            case 24:order=amRoster.getD24();break;
            case 25:order=amRoster.getD25();break;
            case 26:order=amRoster.getD26();break;
            case 27:order=amRoster.getD27();break;
            case 28:order=amRoster.getD28();break;
            case 29:order=amRoster.getD29();break;
            case 30:order=amRoster.getD30();break;
            case 31:order=amRoster.getD31();break;
        }
        return order;
    }


}
